package com.tiancheng.trade.payment.mapper;

import com.tiancheng.trade.payment.channel.bo.RefundSettleBO;
import com.tiancheng.trade.payment.model.IntRefundFlow;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@Repository
public interface IntRefundFlowMapper extends TYBaseMapper<IntRefundFlow> {

    /**
     * 根据支付流水统计退款总金额
     *
     * @param payFlowId
     * @return
     */
    @Select("select COALESCE(sum(amount), 0) from int_refund_flow where pay_flow_id = #{payFlowId} and refund_status in ('wait', 'success')")
    long sumAmountByPayFlowId(@Param("payFlowId") String payFlowId);

    /**
     * 根据商户查询应清分退款流水
     *
     * @param merchants {@link Collection <String>}
     * @return {@link List<RefundSettleBO>}
     */
    List<RefundSettleBO> listSettleRefund(@Param("collection") Collection<String> merchants);

    /**
     * 查询清分支付流水对应的当日退款成功退款流水
     *
     * @param flowDetailIds
     * @return
     */
    List<RefundSettleBO> listApprRefund(@Param("flowDetailIds") List<Long> flowDetailIds);

    /**
     * 退款流水明细批量更新-所更新字段值相同
     *
     * @param ids       id
     * @param colValMap 字段-值：(column, value)
     * @return
     */
    Integer updateSettleBatch(@Param("ids") List<Long> ids, @Param("colValMap") Map<String, Object> colValMap);

}
